import kubernetes
from kubernetes import client, config

import urllib3


config.kube_config.load_kube_config(
    config_file="~/.kube/test")
configuration = kubernetes.client.Configuration()
# cat  ./master |grep client-certificate-data | awk -F ' ' '{print $2}' |base64 -d > client-cert.pem
# cat  ./master |grep client-key-data | awk -F ' ' '{print $2}' |base64 -d > client-key.pem
# cat  ./master |grep certificate-authority-data  | awk -F ' ' '{print $2}' |base64 -d >> client-cert.pem

def k8s_urlib3_master_api():
    url = "https://172.16.0.xx:6443"
    key_file = "/etc/kube-config/master/client-key.pem"
    cert_file = "/etc/kube-config/master/client-cert.pem"
    http = urllib3.PoolManager(
        key_file=key_file, cert_file=cert_file, ca_certs=cert_file)
    return http, url


def k8s_urlib3_test_api():
    url = "https://172.16.0.xx:6443"
    key_file = "/etc/kube-config/test/client-key.pem"
    cert_file = "/etc/kube-config/test/client-cert.pem"

    http = urllib3.PoolManager(
        key_file=key_file, cert_file=cert_file, ca_certs=cert_file)
    return http, url


def getservicename(n):
    arry = []
    v1 = client.CoreV1Api()
    service = v1.list_namespaced_service(namespace=n, watch=False)
    for i in service.items:
        svc_info = {}
        svc_info["service_name"] = i.metadata.name

        arry.append(svc_info)

    return arry
